package A1_二叉树;

import static java.lang.Math.min;

public class LC_111二叉树的最小深度 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val=val;
        }
        TreeNode(int val, TreeNode left, TreeNode right){
            this.val=val;
            this.left=left;
            this.right=right;
        }
        public int minDepth(TreeNode root) {
            if(root==null)
                return 0;
            int leftheight=minDepth(root.left);//zuo
            int rightheight=minDepth(root.right);//you
            //中
            if(root.left==null && root.right!=null)
                return 1+rightheight;
            if(root.left!=null && root.right==null)
                return 1+leftheight;
            int result=1+min(leftheight,rightheight);
            return result;
        }
    }
}
